/**
 * 
 */
package com.swim.common.web;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.sys.entity.User;
import com.jeesite.modules.sys.utils.UserUtils;
import com.swim.common.entity.CommonResults;
import com.swim.common.entity.CommonVO;
import com.swim.common.service.CommonService;
import com.swim.natatoriumapply.entity.NatatoriumApply;

/**
 * @program     : swim
 * @description : 公共api控制层
 * @author      : 刘军武
 * @version     : 1.0  
 * @create      : 2021年3月2日 下午6:47:08
 **/
@Controller
@RequestMapping(value = "${adminPath}/common")
public class CommonController extends BaseController {
	
	@Autowired
	private CommonService commonService;
	
	/**
	 * 根据“字典类型”、“字典值”查询对应字段名称
	 */
	@RequestMapping(value = "getDictLabelByDictTypeAndDictValue")
	@ResponseBody
	public String getDictLabelByDictTypeAndDictValue(String dictType, String dictValue) {
		return commonService.getDictLabelByDictTypeAndDictValue(dictType, dictValue);
	}
	
	/**
	 * 根据“字典类型”查询字典所有明细项
	 */
	@RequestMapping(value = "getDictDataByDictType")
	@ResponseBody
	public List<CommonVO> getDictDataByDictType(String dictType) {
		return commonService.getDictDataByDictType(dictType);
	}
	
	/**
	 * 校验sessionId是否过期
	 * @param natatoriumApply (为了接收SessionId)
	 */
	@RequestMapping(value = "checkSessionId")
	@ResponseBody
	public CommonResults checkSessionId(NatatoriumApply natatoriumApply) {
		CommonResults commonResults = new CommonResults();
		User user = UserUtils.getUser();
		if (StringUtils.isNotEmpty(user.getId())) {
			commonResults.setResult(Global.TRUE);
			commonResults.setMessage("sessionId未过期");
		} else {
			commonResults.setResult(Global.FALSE);
			commonResults.setMessage("sessionId已过期");
		}
		return commonResults;
	}
	
}